<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ page import="com.google.appengine.api.datastore.KeyFactory" %>
<%@ page import="com.google.appengine.api.datastore.Key" %>
<%@ page import="com.honkentuber.*" %>
<%@ page import="com.honkentuber.chat.*" %>
<%@ page import="java.util.List" %>
<%
  // TODO(ptucker) do not serve JSP publicly
  Room room = (Room) request.getAttribute("room");
  List<Message> msgs = (List<Message>) request.getAttribute("msgs");
  Key userKey = (Key) request.getAttribute("userKey");
  MyUserCache userCache = (MyUserCache) request.getAttribute("userCache");
  MyUser user = userCache.getUsers().get(userKey);
  if (user != null) {
%>
<html><head>
<title><%=room.getName()%></title>
<script src="/js/chat.js"></script>
</head><body>
<p>Hello, <%=user.getNickName()%>! (You can <a
  href="<%= request.getAttribute("logoutUrl") %>">sign
out</a>.)</p>
<%
  } else {
%>
<p>Hello! <a
  href="<%= request.getAttribute("loginUrl") %>">Sign
in</a> to include your name with greetings you post.</p>
<%
  }
%>

<div id=title></div>
<div id=msgs></div>
<div id=pending style="display:none">
  <span id=pending-content></span> <img src="img/spinner.gif">
</div>
<div id=compose-container><textarea id=compose></textarea></div>
<input id=submit type=button onclick="chat.send();" value=Send>

<p><a href="/roomlist?html=1">Choose another room</p>
<script>
chat.init(<%= request.getAttribute("userJson") %>,
    <%= request.getAttribute("roomJson") %>,
    <%= request.getAttribute("msgsJson") %>);
</script>
</body></html>